package com.icehand.demo.exception;

import com.icehand.demo.enums.ResultCodeEnums;
import com.icehand.demo.vo.BaseResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class DemoExceptionHandler {

    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public BaseResultVO handleBizException(BizException bizE){
        log.error("BizException =======> code【{}】, msg 【{}】",bizE.getCode(),bizE.getMsg());
        return new BaseResultVO(bizE.getCode(), bizE.getMsg());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public BaseResultVO handleException(Exception e){
        log.error("Exception =======> {}", e);
        return new BaseResultVO<>(ResultCodeEnums.SERVICE_ERROR);
    }
}
